#Boa:Dialog:Dialog1

import wx

def create(parent , app ):
    return Dialog1(parent , app )

[wxID_DIALOG1, wxID_DIALOG1BUTTONANSWER, wxID_DIALOG1BUTTONREFRESH, 
 wxID_DIALOG1LISTBOXMESSAGES, 
] = [wx.NewId() for _init_ctrls in range(4)]

class Dialog1(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
              pos=wx.Point(165, 294), size=wx.Size(671, 207),
              style=wx.DEFAULT_DIALOG_STYLE, title=u'Messages')
        self.SetClientSize(wx.Size(663, 180))
        self.Bind(wx.EVT_INIT_DIALOG, self.OnButtonRefreshButton)

        self.listBoxMessages = wx.ListBox(choices=[],
              id=wxID_DIALOG1LISTBOXMESSAGES, name=u'listBoxMessages',
              parent=self, pos=wx.Point(8, 8), size=wx.Size(648, 136), style=0)

        self.buttonRefresh = wx.Button(id=wxID_DIALOG1BUTTONREFRESH,
              label=u'Refresh', name=u'buttonRefresh', parent=self,
              pos=wx.Point(8, 152), size=wx.Size(75, 23), style=0)
        self.buttonRefresh.Bind(wx.EVT_BUTTON, self.OnButtonRefreshButton,
              id=wxID_DIALOG1BUTTONREFRESH)

        self.buttonAnswer = wx.Button(id=wxID_DIALOG1BUTTONANSWER,
              label=u'Answer', name=u'buttonAnswer', parent=self,
              pos=wx.Point(580, 152), size=wx.Size(75, 23), style=0)
        self.buttonAnswer.Bind(wx.EVT_BUTTON, self.OnButtonAnswerButton,
              id=wxID_DIALOG1BUTTONANSWER)

    def __init__(self, parent, app ):
        self._init_ctrls(parent)
        self.app = app
        self.game_started = False
        self.OnButtonRefreshButton( None )
        self.SetTitle( self.app.player_name + ': messages' )

    def OnButtonRefreshButton(self, event):
        msgs = self.app.server_proxy.enum_messages()
        npos = self.listBoxMessages.GetCount()
        self.listBoxMessages.InsertItems( msgs , npos)
        
        for m in msgs:
            if( m.find("game started") != -1 and m.find("server") != -1 ):
                self.game_started = True
                break

    def OnButtonAnswerButton(self, event):
        msg = self.listBoxMessages.GetStringSelection()
        if( msg == '' ):
            return
        n1 = msg.find('<')
        n2 = msg.find('>')
        if( n1 == -1 or n2 == -1 ):
            return 
        player_name = msg[ n1+1 : n2 ]
        self.app.dialog_enter_message.enemy_name = player_name 
        self.app.dialog_enter_message.ShowModal()
